home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / EnterBox / EnterBox.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  8.6 KB  |  329 lines

  1. import java.applet.Applet;
  2. import java.awt.Button;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.Dialog;
  7. import java.awt.Frame;
  8. import java.awt.GridLayout;
  9. import java.awt.Insets;
  10. import java.awt.LayoutManager;
  11. import java.awt.TextArea;
  12. import java.awt.TextComponent;
  13. import java.awt.Toolkit;
  14. import java.awt.event.ActionEvent;
  15. import java.awt.event.ActionListener;
  16. import java.awt.event.WindowEvent;
  17. import java.awt.event.WindowListener;
  18. import java.io.BufferedReader;
  19. import java.io.InputStream;
  20. import java.io.InputStreamReader;
  21. import java.net.MalformedURLException;
  22. import java.net.URL;
  23. import java.net.URLEncoder;
  24. import java.util.EventObject;
  25.  
  26. public class EnterBox extends Applet implements WindowListener, ActionListener {
  27.    public String url;
  28.    // $FF: renamed from: wi int
  29.    private int field_0;
  30.    // $FF: renamed from: he int
  31.    private int field_1;
  32.    private String agreeText;
  33.    private String disagreeText;
  34.    private Dialog dialog;
  35.    private int mode;
  36.    private String text;
  37.    private String file;
  38.  
  39.    public String getAppletInfo() {
  40.       return "Name: EnterBox\r\nAuthor: Taiji Software\r\n";
  41.    }
  42.  
  43.    public void register() {
  44.       try {
  45.          URL u = new URL("http://www.taijisoftware.com");
  46.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  47.       } catch (Exception e) {
  48.          System.out.println(e);
  49.          this.stop();
  50.       }
  51.    }
  52.  
  53.    public void init() {
  54.       String codeBase = null;
  55.  
  56.       try {
  57.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  58.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  59.          codeBase = codeBase.toUpperCase();
  60.       } catch (Exception var9) {
  61.       }
  62.  
  63.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  64.          String regCode = ((Applet)this).getParameter("registration_code");
  65.          if (regCode == null) {
  66.             regCode = ((Applet)this).getParameter("reg_domain");
  67.             if (regCode == null) {
  68.                this.register();
  69.             } else {
  70.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  71.                   codeBase = "WWW." + codeBase;
  72.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  73.                   codeBase = codeBase.substring(4);
  74.                }
  75.  
  76.                char[] chars = new char[codeBase.length()];
  77.                codeBase.getChars(0, codeBase.length(), chars, 0);
  78.                String key = new String("haricot");
  79.                char[] chars2 = new char[key.length()];
  80.                key.getChars(0, key.length(), chars2, 0);
  81.  
  82.                for(int i = 0; i < codeBase.length(); ++i) {
  83.                   int j;
  84.                   if (i >= key.length()) {
  85.                      j = i - key.length() * (i / key.length());
  86.                   } else {
  87.                      j = i;
  88.                   }
  89.  
  90.                   chars[i] += chars2[j];
  91.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  92.                }
  93.  
  94.                String res = new String(chars);
  95.                if (!res.equalsIgnoreCase(regCode)) {
  96.                   this.register();
  97.                }
  98.             }
  99.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  100.             this.register();
  101.          }
  102.       }
  103.  
  104.       this.getParameters();
  105.       this.putComponents();
  106.    }
  107.  
  108.    public void stop() {
  109.       if (this.dialog != null && this.dialog.isShowing()) {
  110.          this.dialog.dispose();
  111.       }
  112.  
  113.    }
  114.  
  115.    public void getParameters() {
  116.       this.field_0 = ((Component)this).getSize().width;
  117.       this.field_1 = ((Component)this).getSize().height;
  118.       this.agreeText = ((Applet)this).getParameter("button_agree_text");
  119.       if (this.agreeText == null) {
  120.          this.agreeText = "I agree";
  121.       }
  122.  
  123.       this.disagreeText = ((Applet)this).getParameter("button_disagree_text");
  124.       if (this.disagreeText == null) {
  125.          this.disagreeText = "I don't agree";
  126.       }
  127.  
  128.       ((Component)this).setBackground(this.getColor("background_color"));
  129.       this.file = ((Applet)this).getParameter("file");
  130.    }
  131.  
  132.    public Color getColor(String param) {
  133.       String s = ((Applet)this).getParameter(param);
  134.       if (s != null) {
  135.          if (s.substring(0, 1).equals("#")) {
  136.             s = s.substring(1);
  137.             int i = Integer.parseInt(s, 16);
  138.             return new Color(i);
  139.          } else {
  140.             return null;
  141.          }
  142.       } else {
  143.          return null;
  144.       }
  145.    }
  146.  
  147.    public void putComponents() {
  148.       String s = ((Applet)this).getParameter("frame_width");
  149.       int dialogWidth;
  150.       if (s != null) {
  151.          dialogWidth = Integer.parseInt(s);
  152.       } else {
  153.          dialogWidth = 200;
  154.       }
  155.  
  156.       s = ((Applet)this).getParameter("frame_height");
  157.       int dialogHeight;
  158.       if (s != null) {
  159.          dialogHeight = Integer.parseInt(s);
  160.       } else {
  161.          dialogHeight = 200;
  162.       }
  163.  
  164.       s = ((Applet)this).getParameter("mode");
  165.       if (s != null) {
  166.          this.mode = Integer.parseInt(s);
  167.       }
  168.  
  169.       s = ((Applet)this).getParameter("frame_title");
  170.       if (s == null) {
  171.          s = "Information";
  172.       }
  173.  
  174.       Frame f = new Frame();
  175.       this.dialog = new Dialog(f, s);
  176.       this.dialog.setLayout((LayoutManager)null);
  177.       this.dialog.addWindowListener(this);
  178.       Toolkit toolkit = Toolkit.getDefaultToolkit();
  179.       int width = toolkit.getScreenSize().width;
  180.       int height = toolkit.getScreenSize().height;
  181.       if (((Applet)this).getParameter("frame_background_color") != null) {
  182.          this.dialog.setBackground(this.getColor("frame_background_color"));
  183.       } else {
  184.          this.dialog.setBackground((new Button()).getBackground());
  185.       }
  186.  
  187.       this.dialog.setVisible(true);
  188.       this.dialog.setBounds((width - dialogWidth) / 2, (height - dialogHeight) / 2, dialogWidth, dialogHeight);
  189.       Insets insets = this.dialog.getInsets();
  190.       this.dialog.dispose();
  191.       Button b1 = new Button(this.agreeText);
  192.       Button b2 = new Button(this.disagreeText);
  193.       ((Container)this).add(b1);
  194.       ((Container)this).add(b2);
  195.       int w = ((Component)b1).getPreferredSize().width;
  196.       int w2 = ((Component)b2).getPreferredSize().width;
  197.       if (w2 > w) {
  198.          w = w2;
  199.       }
  200.  
  201.       ((Container)this).remove(b1);
  202.       ((Container)this).remove(b2);
  203.       this.dialog.add(b1);
  204.       this.dialog.add(b2);
  205.       b1.addActionListener(this);
  206.       b2.addActionListener(this);
  207.       int space = (dialogWidth - 2 * w) / 3;
  208.       ((Component)b1).setBounds(space, dialogHeight - 25 - insets.bottom - 20, w, 25);
  209.       ((Component)b2).setBounds(2 * space + w, dialogHeight - 25 - insets.bottom - 20, w, 25);
  210.       TextArea textarea = new TextArea();
  211.       ((TextComponent)textarea).setEditable(false);
  212.       this.dialog.add(textarea);
  213.       ((Component)textarea).setBounds(10, insets.top + 20, dialogWidth - 20, ((Component)b1).getLocation().y - 20 - insets.top - 20);
  214.  
  215.       try {
  216.          InputStream in = null;
  217.          in = (new URL(((Applet)this).getCodeBase(), this.file)).openStream();
  218.          BufferedReader br = new BufferedReader(new InputStreamReader(in));
  219.  
  220.          String s2;
  221.          while((s2 = br.readLine()) != null) {
  222.             textarea.append(s2 + "\r\n");
  223.          }
  224.  
  225.          br.close();
  226.       } catch (Exception ee) {
  227.          System.err.println(ee);
  228.       }
  229.  
  230.       s = ((Applet)this).getParameter("button_show_text");
  231.       if (s == null) {
  232.          s = "Enter !";
  233.       }
  234.  
  235.       if (this.mode == 0) {
  236.          Button showButton = new Button(s);
  237.          showButton.addActionListener(this);
  238.          ((Container)this).setLayout(new GridLayout(1, 1));
  239.          ((Container)this).add(showButton);
  240.       } else {
  241.          this.dialog.show();
  242.          System.out.println(dialogHeight);
  243.          System.out.println(this.dialog.getSize().height);
  244.       }
  245.    }
  246.  
  247.    public void actionPerformed(ActionEvent event) {
  248.       if (((EventObject)event).getSource() instanceof Button) {
  249.          String s = ((Button)((EventObject)event).getSource()).getLabel();
  250.          if (s.equals(this.agreeText)) {
  251.             this.quitDialog(true);
  252.          } else if (s.equals(this.disagreeText)) {
  253.             this.quitDialog(false);
  254.          } else {
  255.             this.dialog.show();
  256.          }
  257.       }
  258.    }
  259.  
  260.    public void quitDialog(boolean agree) {
  261.       String link;
  262.       if (agree) {
  263.          link = ((Applet)this).getParameter("agree_link");
  264.       } else {
  265.          link = ((Applet)this).getParameter("disagree_link");
  266.       }
  267.  
  268.       if (link != null) {
  269.          String target = ((Applet)this).getParameter("target");
  270.          if (target == null) {
  271.             target = "_blank";
  272.          }
  273.  
  274.          URL u = this.giveURL(link);
  275.          ((Applet)this).getAppletContext().showDocument(u, target);
  276.       }
  277.  
  278.       this.dialog.dispose();
  279.    }
  280.  
  281.    public void windowClosing(WindowEvent e) {
  282.       this.quitDialog(false);
  283.    }
  284.  
  285.    public void windowClosed(WindowEvent e) {
  286.    }
  287.  
  288.    public void windowOpened(WindowEvent e) {
  289.    }
  290.  
  291.    public void windowIconified(WindowEvent e) {
  292.    }
  293.  
  294.    public void windowDeiconified(WindowEvent e) {
  295.    }
  296.  
  297.    public void windowActivated(WindowEvent e) {
  298.    }
  299.  
  300.    public void windowDeactivated(WindowEvent e) {
  301.    }
  302.  
  303.    public URL giveURL(String url) {
  304.       try {
  305.          if (url.toUpperCase().startsWith("HTTP")) {
  306.             return new URL(url);
  307.          } else if (url.toUpperCase().startsWith("FTP")) {
  308.             int p = url.indexOf(":");
  309.             int p2 = url.indexOf(":", p + 1);
  310.             if (p2 != -1) {
  311.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  312.             }
  313.  
  314.             p = url.indexOf("%40");
  315.             if (p != -1) {
  316.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  317.             }
  318.  
  319.             return new URL(url);
  320.          } else {
  321.             return new URL(((Applet)this).getCodeBase(), url);
  322.          }
  323.       } catch (MalformedURLException e) {
  324.          System.out.println(e);
  325.          return null;
  326.       }
  327.    }
  328. }
  329.